<template>
    <div class="page-main">
        <!-- 轮播图 -->
        <div class="swiper-main" id="swiper-main">
            <a href="#" index="0" class="active-swiper"><img src="../assets/uploads/back-1-4.jpg" alt=""></a>
            <a href="#" index="1"><img src="../assets/uploads/back-1-1.jpg" alt=""></a>
            <a href="#" index="2"><img src="../assets/uploads/back-1-2.jpg" alt=""></a>
            <a href="#" index="2"><img src="../assets/uploads/back-1-3.jpg" alt=""></a>
            <span class="button-left iconfont iconleft"></span>
            <span class="button-right iconfont iconright"></span>
            <!-- 小圆圈 -->
            <div class="bullets">
                <i index="0" class="active"></i>
                <i index="1"></i>
                <i index="2"></i>
                <i index="3"></i>
            </div>
        </div>
        <!-- 具体商品 -->
        <div class="container">
            <!-- 第一种排列 -->
            <h3>明星单品</h3>
            <div class="d-product">
                <a href="#"><img src="../assets/uploads/phone-2.jpg" alt=""></a>
                <span>
                    <a href="#">Redmi 10X 5G 系列</a>
                    <em>双5G待机，天玑820处理器，4800万流光相机</em><br/>
                    <font>1599<i>元起</i></font><br/>
                    <a href="#">立即购买</a>
                </span>
            </div>
            <div class="d-product">
                <a href="#"><img src="../assets/uploads/phone-3.jpg" alt=""></a>
                <span>
                    <a href="#">Redmi 10X 5G 系列</a>
                    <em>双5G待机，天玑820处理器，4800万流光相机</em><br/>
                    <font>1599<i>元起</i></font><br/>
                    <a href="#">立即购买</a>
                </span>
            </div>
            <div class="d-product">
                <a href="#"><img src="../assets/uploads/phone-4.jpg" alt=""></a>
                <span>
                    <a href="#">Redmi 10X 5G 系列</a>
                    <em>双5G待机，天玑820处理器，4800万流光相机</em><br/>
                    <font>1599<i>元起</i></font><br/>
                    <a href="#">立即购买</a>
                </span>
            </div>
            <!-- 第二种排列 -->
            <div class="components-list-box">
                <div class="channel-produt-cell-1">
                    <a href="#"><img src="../assets/uploads/phone-5.jpg" alt=""></a>
                    <span>
                        <a href="#">小米10</a>
                        <em>骁龙865/1亿像素相机 </em><br/>
                        <font>3999<i>元起</i></font><br/>
                    </span>
                </div>
                <div class="channel-produt-cell-2">
                    <a href="#"><img src="../assets/uploads/phone-6.jpg" alt=""></a>
                    <span>
                        <a href="#">小米10</a>
                        <em>骁龙865/1亿像素相机 </em><br/>
                        <font>3999<i>元起</i></font><br/>
                    </span>
                </div>
            </div>
            <div class="components-list-box">
                <div class="channel-produt-cell-1">
                    <a href="#"><img src="../assets/uploads/phone-7.jpg" alt=""></a>
                    <span>
                        <a href="#">小米10</a>
                        <em>骁龙865/1亿像素相机 </em><br/>
                        <font>3999<i>元起</i></font><br/>
                    </span>
                </div>
                <div class="channel-produt-cell-2">
                    <a href="#"><img src="../assets/uploads/phone-8.jpg" alt=""></a>
                    <span>
                        <a href="#">小米10</a>
                        <em>骁龙865/1亿像素相机 </em><br/>
                        <font>3999<i>元起</i></font><br/>
                    </span>
                </div>
            </div>
        </div>
    </div>
</template>
<script>

import $ from 'jquery';

// import Header from '../components/Header'
// import Footer from '../components/Footer'
export default {
    components:{
        // 'header-quan':Header,
        // 'footer-quan':Footer
    },
    mounted() {
        this.startSwiper()
        this.show_category()
    },
    methods: {
        // 展示分类
        show_category(){
            $(".nav-category .category-a").css("visibility","visible")
            $(".home-hero-category").css("visibility","hidden")
            $(".nav-category .category-list").css("background-color","#fff")
            $(".nav-category .category-list a").css("color","#757575")
            $(".nav-category .category-list").css("border","1px solid #ff6700")
        },

        // 淡入淡出的轮播图
        startSwiper(){
            var button_right=document.querySelector(".button-right")
            var button_left=document.querySelector(".button-left")
            var a=document.querySelectorAll(".swiper-main a")
            var swiper_main=document.getElementById("swiper-main")
            var dot=document.querySelector(".bullets")
            // console.log(dot.children.length)
            var index=0
            button_right.addEventListener('click',()=>{
                index=index<a.length-1?++index:0
                for(var i=0;i<a.length;i++){
                    // 为diaplay: none;这个属性添加过度动画是无效的，他的任何不同状态值之间的切换总是会立即生效。
                    a[i].style.opacity="0"
                }
                a[index].style.opacity="1"
                circleChang()
            })
            button_left.addEventListener("click",()=>{
                index=index==0?a.length-1:--index
                for(var i=0;i<a.length;i++){
                    a[i].style.opacity="0"
                }
                a[index].style.opacity="1"
                circleChang()
            })
            //自动播放
            var timer=setInterval(function(){
                button_right.click()
            },4000)
            // 鼠标进入背景图才显示按钮
            swiper_main.addEventListener('mouseenter',()=>{
                button_right.style.display="block"
                button_left.style.display="block"
                // 鼠标在上面就不要自动轮播 清除定时器
                clearInterval(timer)
                timer=null
            })
            swiper_main.addEventListener('mouseleave',()=>{
                button_right.style.display="none"
                button_left.style.display="none"
                // 鼠标在上面就不要自动轮播 清除定时器
                timer=setInterval(function(){
                    button_right.click()
                },4000)
            })
            //点击小圈也可以切换
            for(var i=0;i<dot.children.length;i++){
                dot.children[i].addEventListener('click',function(){
                    for(var i=0;i<dot.children.length;i++){
                        dot.children[i].className=""
                    }
                    this.className="active"
                    // 拿到索引
                    index=this.getAttribute('index')
                    for(var i=0;i<a.length;i++){
                        a[i].style.opacity="0"
                    }
                    a[index].style.opacity="1"
                })
            }
            // 小圈圈的改变
            function circleChang(){
                // console.log(dot.children[circle])
                for(var i=0;i<dot.children.length;i++){
                    dot.children[i].className=""
                }
                dot.children[index].className="active"
            }
        }
    },
}
</script>
<style scoped>
.page-main{
    background-color: #f5f5f5;
}
.container{
    width: 1226px;
    margin-left: auto;
    margin-right: auto;
}
/* logo轮播图 */
.swiper-main{
    position: relative;
    overflow: hidden;
    height: 620px;
}
.swiper-main a{
    position: absolute;
    top: 0;
    left: 0;
    transition: all 3s;
    opacity: 0;
}
.swiper-main img{
    display: block;
    height: 620px;
    margin-left: -500px;
}
.swiper-main .button-right{
    text-align: center;
    line-height: 50px;
    position: absolute;
    top: 40%;
    right: 160px;
    display: none;
    width: 30px;
    height: 50px;
}
.swiper-main .button-left{
    line-height: 50px;
    text-align: center;
    position: absolute;
    top: 40%;
    left: 160px;
    display: none;
    width: 30px;
    height: 50px;
}
.swiper-main span:hover{
    background-color: #ccc;
}
.swiper-main .active-swiper{
    opacity: 1;
}
/* 小圆圈 */
.bullets{
    position: absolute;
    width: 100px;
    bottom: 60px;
    text-align: right;
    right: 100px;
}
.bullets i{
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 6px;
    border: 2px solid #ccc;
    background: rgba(0,0,0,.4);
    margin: 0 2px;
}
.bullets .active{
    background-color: #fff;
}
/* 明星单品 第一种排列 */
.page-main .container h3{
    line-height: 64px;
    color: #333;
    font-size: 24px;
    font-weight: 400;
    padding-top: 4px;
}
.page-main .container .d-product{
    position: relative;
    height: 434px;
    width: 1226px;
    transition: all .4s;
}
.container .d-product a img{
    display: block;
    width: 854px;
    height: 434px;
}
.d-product span{
    position: absolute;
    top: 0;
    right: 0;
    height: 434px;
    width: 372px;
    text-align: center;
    background-color: #fff;
}
.d-product span a:nth-child(1){
    display: block;
    padding-top: 90px;
    line-height: 35px;
    text-align: left;
    margin: 0 50px;
    font-weight: 400;
    font-size: 32px;
    color: rgba(51, 51, 51, .9);
}
.d-product span em{
    display: block;
    line-height: 24px;
    text-align: left;
    margin: 0 50px;
    color: rgba(51, 51, 51, .7);
    font-size: 14px;
}
.d-product span font{
    display: block;
    line-height: 45px;
    text-align: left;
    margin: 0 50px;
    font-size: 32px;
    font-weight: 700;
    color: #ff6700;
}
.d-product span font i{
    font-size: 12px;
}
.d-product span a:last-child{
    color: rgba(51,51,51,.7);
    font-size: 14px;
    padding-top: 40px;
    text-align: left;
    display: block;
    margin: 0 50px;
}
.d-product:hover{
    box-shadow:0 15px 30px rgba(0, 0, 0, .1);
    transform: translate3d(0,-5px,0);
}
/* 第二种排列 */
.components-list-box{
    width: 1226px;
    overflow: hidden;
}
.channel-produt-cell-1,.channel-produt-cell-2{
    margin-top: 30px;
    margin-bottom: 30px;
    display: inline-block;
    width: 606px;
    position: relative;
    height: 100%;
    background: #fff;
    text-align: left;
    overflow: hidden;
    margin-right: 12px;
    transition: all .4s;
}
.channel-produt-cell-2{
    margin-right: 0;
}
.components-list-box img{
    display: block;
    height: 358px;
    width: 100%;
}
.channel-produt-cell-txt{
    position: relative;
    font-size: 12px;
}
.components-list-box span a{
    display: block;
    font-weight: 400;
    white-space: nowrap;
    text-overflow: ellipsis;
    line-height: 26px;
    margin: 38px 0 0 48px;
    font-size: 24px;
    color: rgba(51, 51, 51, .9);
}
.components-list-box em{
    display: block;
    line-height: 18px;
    margin: 3px 0 0 48px;
    color: #333;
    color: rgba(51,51,51,.7);
    font-size: 14px;
    padding-bottom: 20px;
}
.components-list-box font{
    line-height: 30px;
    color: #ff6700;
    font-size: 32px;
    font-weight: 400;
    position: absolute;
    right: 48px;
    bottom: 48px;
    margin: 0;
}
.components-list-box font i{
    font-size: 12px;
}
.channel-produt-cell-1:hover{
    box-shadow:0 15px 30px rgba(0, 0, 0, .1);
    transform: translate3d(0,-5px,0);
}
.channel-produt-cell-2:hover{
    box-shadow:0 15px 30px rgba(0, 0, 0, .1);
    transform: translate3d(0,-5px,0);
}
</style>